//
//  WBStatuses.swift
//  czWB
//
//  Created by Qing on 2018/11/21.
//  Copyright © 2018年 成哥哥. All rights reserved.
//

import Foundation


/// 微博数据模型
@objcMembers class WBStatuses: NSObject {
    
    /// 微博ID
    var id: Int64 = 0
    
    /// 微博信息内容
    var text: String?
    
    /// 微博来源
    var source: String?
    
    /// 单条用户微博信息
    var user: WBUser?
    
    /// 转发数
    var reposts_count: Int = 0
    /// 评论数
    var comments_count: Int = 0
    /// 点赞数
    var attitudes_count: Int = 0
    
    /// 单条微博配图urls
    var pic_urls: WBPic_urls?//WBPic_urls?
    
    init(dict: [String: Any]) {
        
        super.init()
        
        setValuesForKeys(dict)
        
    }
    
//    如果key是user，则再次kvc赋值。
    override func setValue(_ value: Any?, forKey key: String) {
        
//        if key == "pic_urls" {
//
//            if let dict = value as? [String: Any] {
//
//
//                    pic_urls = WBPic_urls(dict: dict)
//
//                    return
//
//            }
//
//        }
//        super.setValue(value, forKey: key)

        if key == "user" {

            if let dict = value as? [String: Any] {

                user = WBUser(dict: dict)

                return
            }}
        
            super.setValue(value, forKey: key)
        
    }
    
//
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
//        找不到成员会转来这里
//        print("找不到\(key)")
    }
    
    override var description: String {
        
        let keys = ["id", "text", "user", "source", "reposts_count", "comments_count", "attitudes_count", "pic_urls"]
        
        return dictionaryWithValues(forKeys: keys).description
        
    }
    

    
}
